package com.yztc.youbadbad.presenter;

import android.util.Log;

import com.yztc.youbadbad.bean.other.ProductInfoBean;
import com.yztc.youbadbad.model.ProductInfoModelImpl;
import com.yztc.youbadbad.ui.other.activity.interfaces.CommodityInfoInterfaces;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 商品详情的实现类
 * Created by Tiffany.V.Chou on 2016/11/18.
 */

public class ProductInfoPresenterImpl implements CommodityInfoInterfaces.IProductInfoPresenter {
    private CommodityInfoInterfaces.IProductInfoView iProductInfoView = null;
    private CommodityInfoInterfaces.IProductInfoModel iProductInfoModel = null;

    public ProductInfoPresenterImpl(CommodityInfoInterfaces.IProductInfoView iProductInfoView) {
        this.iProductInfoView = iProductInfoView;
        this.iProductInfoModel = new ProductInfoModelImpl();
    }

    @Override
    public void getProdectInfoInternetData(String product_id) {
        iProductInfoModel.getProdectInfoObservable(product_id)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Subscriber<ProductInfoBean>() {
                    @Override
                    public void onCompleted() {
                        iProductInfoView.hideProgressBar();

                        Log.e("tag", "onCompleted===========>");
                    }

                    @Override
                    public void onError(Throwable e) {
                        iProductInfoView.hideProgressBar();
                        iProductInfoView.showErrorMessage();
                        Log.e("tag", e.getMessage()+"-------------------error---");
                    }

                    @Override
                    public void onNext(ProductInfoBean productInfoBean) {
                        iProductInfoView.getProdectInfoInternetData(productInfoBean);
                        Log.e("tag", "onNext---"+productInfoBean.getData().getBrandInfo().getContent());
                    }
                });
    }
}
